//
//  OrderCell.m
//  Manager
//
//  Created by 彭凯敏 on 15/8/18.
//  Copyright (c) 2015年 52xiaoluo. All rights reserved.
//

#import "OrderCell.h"

@implementation OrderCell



- (IBAction)clickBtn:(UIButton *)sender {
    
    if (_delegate && [_delegate respondsToSelector:@selector(orderCellCallPhone: andCell:)]) {
        
        [_delegate orderCellCallPhone:sender andCell:self];
    }
    
}
- (IBAction)clickOrder:(UIButton *)sender {
    
    if (_delegate && [_delegate respondsToSelector:@selector(orderCellGetNewOrder: andCell:)]) {
        
        [_delegate orderCellGetNewOrder:sender andCell:self];
    }
}

- (void)setCellOrder:(ViewOrder *)cellOrder
{
    _cellOrder = cellOrder;
    
    _nameLabel.text = [cellOrder.name judgeWithBase:@""];
    
    [self roomWith:@"预约" withtime:cellOrder.viewTime];

    
    if (cellOrder.status == 1) {
        _phoneBtn.hidden = YES;
        _orderBtn.hidden = NO;
        _btnAssisLabel.textColor = [UIColor redColor];
        
        [self exceedTimeWith:_cellOrder.createTime/1000];
    }
    else if (cellOrder.status == 2)
    {
        _phoneBtn.hidden = NO;
        _orderBtn.hidden = YES;
        
//        BOOL isExceed = [self isExceedMinutes:cellOrder.orderStewardTime/1000];
//        
//        _btnAssisLabel.textColor = isExceed?[UIColor redColor]:[UIColor redColor];
        _btnAssisLabel.textColor = [UIColor redColor];
        [self exceedTimeWith:_cellOrder.orderStewardTime/1000];
    }
    
}

- (void)roomWith:(NSString *)textStr withtime:(UInt64)time
{
    _timeLabel.text = [NSString stringWithFormat:@"%@时间：%@",textStr,[KMGetDate timeFromNum:[NSString stringWithFormat:@"%llu",time/1000] andFormStr:@"YYYY-MM-dd HH:mm"]];
    
    if (!_cellOrder.viewRooms) {
        _roomLabel1.text = [NSString stringWithFormat:@"%@房间：无",textStr];
        _statusLabel.text = @"";
        
    }
    else
    {
        RoomInfo *info = _cellOrder.viewRooms[0];
        _roomLabel1.text = [info.name judgeRoomBase:[NSString stringWithFormat:@"%@房间：",textStr]];
        
        _statusLabel.text = [UIViewCategory roomStatusWith:info];
        
        if ([info.name isEqualToString:@""]) {
            _roomLabel1.text = [NSString stringWithFormat:@"%@时间：无",textStr];
            _statusLabel.text = @"";
        }
    }
}
//是否超时10分钟
- (void)exceedTimeWith:(UInt64)getTime
{
    if (!_cellOrder) {
        return;
    }
    NSDate *getDate = [NSDate dateWithTimeIntervalSince1970:getTime];
    
    NSDate *nowDate = [NSDate date];
    
    NSTimeInterval time=[nowDate timeIntervalSinceDate:getDate];
    time = 10*60- time;
    int minute = (int)time/60;
    int second = time - minute*60;
    
    NSString *dural;
    if (minute/10 == 0 && second/10 == 0) {
        dural= [NSString stringWithFormat:@"0%d:0%d",minute,second];
    }
    else if (minute/10 != 0 && second/10 == 0) {
        dural= [NSString stringWithFormat:@"%d:0%d",minute,second];
    }
    else if (minute/10 == 0 && second/10 != 0)
    {
        dural = [NSString stringWithFormat:@"0%d:%d",minute,second];
    }
    else
    {
        dural = [NSString stringWithFormat:@"%d:%d",minute,second];
    }
    if (time<0) {
        dural = @"超时十分钟";
    }
    else if (time >= 10*60)
    {
        dural = @"10:00";
    }
    _btnAssisLabel.text = dural;
}
//是否超时10分钟
- (BOOL)isExceedMinutes:(UInt64)getTime
{
    NSDate *getDate = [NSDate dateWithTimeIntervalSince1970:getTime];
    
    NSDate *nowDate = [NSDate date];
    
    NSTimeInterval time=[nowDate timeIntervalSinceDate:getDate];
    
    if (time>10*60 || time<0) {
        return YES;
    }
    else
    {
        return NO;
    }
}

@end
